


import numpy as np


def calc_actual_chg(preClose: float, close: float) -> float:
    """计算实际涨幅"""
    return (close - preClose) / preClose * 100

def get_klines_range(start_index:int,klines_len:int,limit:int):
    max_index=min(start_index+limit,klines_len-1)
    temporary_min_index=max_index-limit
    min_index=max(temporary_min_index,0)

    return {"min":min_index,"max":max_index}


def get_range_volume_mean(klines:list,index:int,limit:int):
    range=get_klines_range(index,len(klines),limit)
    kline_range=klines[range["min"]:range["max"]]
    avg_volume=np.mean([kline["volume"] for kline in kline_range])
    return avg_volume
    